home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 741 / rkrm_lib1 / rkrm_lib1.lha / ASL / filehook.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  5KB  |  143 lines

  1. ;/* filehook.c - Execute me to compile me with Lattice 5.10
  2. LC -b1 -cfistq -v -y -j73 filehook.c
  3. Blink FROM LIB:c.o,filehook.o TO filehook LIBRARY LIB:LC.lib,LIB:Amiga.lib
  4. quit
  5. */
  6.  
  7. /*
  8. Copyright (c) 1992 Commodore-Amiga, Inc.
  9.  
  10. This example is provided in electronic form by Commodore-Amiga, Inc. for
  11. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  12. published by Addison-Wesley (ISBN 0-201-56774-1).
  13.  
  14. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  15. information on the correct usage of the techniques and operating system
  16. functions presented in these examples.  The source and executable code
  17. of these examples may only be distributed in free electronic form, via
  18. bulletin board or as part of a fully non-commercial and freely
  19. redistributable diskette.  Both the source and executable code (including
  20. comments) must be included, without modification, in any copy.  This
  21. example may not be published in printed form or distributed with any
  22. commercial product.  However, the programming techniques and support
  23. routines set forth in these examples may be used in the development
  24. of original executable software products for Commodore Amiga computers.
  25.  
  26. All other rights reserved.
  27.  
  28. This example is provided "as-is" and is subject to change; no
  29. warranties are made.  All use is at your own risk. No liability or
  30. responsibility is assumed.
  31. */
  32.  
  33. #include <exec/types.h>
  34. #include <intuition/intuition.h>
  35. #include <dos/dosasl.h>
  36. #include <libraries/asl.h>
  37.  
  38. #include <clib/exec_protos.h>
  39. #include <clib/dos_protos.h>
  40. #include <clib/asl_protos.h>
  41. #include <clib/intuition_protos.h>
  42. #include <stdio.h>
  43.  
  44. #ifdef LATTICE
  45. int CXBRK(void)     { return(0); }  /* Disable Lattice CTRL/C handling */
  46. void chkabort(void) { return; }     /* really */
  47. #endif
  48.  
  49. #define DESTPATLENGTH 20
  50.  
  51. UBYTE *vers = "$VER: filehook 37.0";
  52.  
  53. CPTR HookFunc();
  54.  
  55. struct Library *AslBase = NULL;
  56. struct Library *IntuitionBase = NULL;
  57. struct Window  *window = NULL;
  58.  
  59. /* this is the pattern matching string that the hook function uses */
  60. UBYTE *sourcepattern = "(#?.info)";
  61. UBYTE pat[DESTPATLENGTH];
  62.  
  63. void main(int argc, char **argv)
  64. {
  65.     struct FileRequester *fr;
  66.  
  67.     if (AslBase = OpenLibrary("asl.library", 37L))
  68.     {
  69.         if (IntuitionBase = (struct IntuitionBase *)
  70.                     OpenLibrary("intuition.library", 37L))
  71.         {
  72.             /* This is a V37 dos.library function that turns a pattern matching
  73.             ** string into something the DOS pattern matching functions can
  74.             ** understand.
  75.             */
  76.             ParsePattern(sourcepattern, pat, DESTPATLENGTH);
  77.  
  78.             /* open a window that gets ACTIVEWINDOW events */
  79.             if (window = (struct Window *)OpenWindowTags(NULL,
  80.                     WA_Title, "ASL Hook Function Example",
  81.                     WA_IDCMP, IDCMP_ACTIVEWINDOW,
  82.                     WA_Flags, WFLG_DEPTHGADGET,
  83.                     TAG_END))
  84.             {
  85.                 if (fr = AllocFileRequest())
  86.                 {
  87.                     if (AslRequestTags(fr,
  88.                         ASL_Dir, (ULONG)"SYS:Utilities",
  89.                         ASL_Window, window,
  90.                         ASL_TopEdge, 0L,
  91.                         ASL_Height, 200L,
  92.                         ASL_Hail, (ULONG)"Pick an icon, select save",
  93.                         ASL_HookFunc, (ULONG)HookFunc,
  94.                         ASL_FuncFlags, FILF_DOWILDFUNC | FILF_DOMSGFUNC | FILF_SAVE,
  95.                         ASL_OKText, (ULONG)"Save",
  96.                         TAG_DONE))
  97.                     {
  98.                         printf("PATH=%s FILE=%s\n", fr->rf_Dir, fr->rf_File);
  99.                         printf("To combine the path and filename, copy the path\n");
  100.                         printf("to a buffer, add the filename with Dos AddPart().\n");
  101.                     }
  102.                     FreeFileRequest(fr);
  103.                 }
  104.                 CloseWindow(window);
  105.             }
  106.             CloseLibrary(IntuitionBase);
  107.         }
  108.         CloseLibrary(AslBase);
  109.     }
  110. }
  111.  
  112.  
  113.  
  114.  
  115. CPTR HookFunc(LONG type, CPTR obj, struct FileRequester *fr)
  116. {
  117.     static BOOL returnvalue;
  118.     switch(type)
  119.     {
  120.         case FILF_DOMSGFUNC:
  121.         /* We got a message meant for the window */
  122.             printf("You activated the window\n");
  123.             return(obj);
  124.             break;
  125.         case FILF_DOWILDFUNC:
  126.         /* We got an AnchorPath structure, should
  127.         ** the requester display this file? */
  128.  
  129.             /* MatchPattern() is a dos.library function that
  130.             ** compares a matching pattern (parsed by the
  131.             ** ParsePattern() DOS function) to a string and
  132.             ** returns true if they match. */
  133.             returnvalue = MatchPattern(pat,
  134.                     ((struct AnchorPath *)obj)->ap_Info.fib_FileName);
  135.  
  136.             /* we have to negate MatchPattern()'s return value
  137.             ** because the file requester expects a zero for
  138.             ** a match not a TRUE value */
  139.             return( (CPTR)(! returnvalue) );
  140.             break;
  141.     }
  142. }
  143.